const bodyparser = require('koa-bodyparser'),
      tasks = require('../models/tasks.js'),
      log = console.log;
const router = require('koa-router')();

router.prefix('/api/tasks');
router.get('/', async(ctx, next) => {
  let res = await tasks.getAllTasks(ctx.userId); 
  ctx.body = res;
});
router.post('/', async(ctx, next) => {
  let {task} = ctx.request.body;
  log(`提交代办事项, task:${task}`);
  ctx.body = '添加成功';
});
router.put('/:id', async(ctx, next) => {
  let {id} = ctx.params;
  let {task} = ctx.request.body;
  log(`修改代办事项, id=${id}, task:${task}`);
  ctx.body = '修改成功';
});
router.delete('/:id', async(ctx, next) => {
  let {id} = ctx.params;
  log(`删除代办事项, id=${id}`);
  ctx.body = '删除成功';
});

module.exports = router;
